<template>
  <div class="views-container">
    <div class="wlm-table">
      <!-- 工具条区域 -->
      <div class="wlm-table-header">
        <el-form
          :model="tableFormatData.cardBagCategory.files"
          size="small"
          label-width="80px"
          class="retail-form"
          label-position="right"
        >
          <el-form-item class="filter">
            <el-form-item label="用户昵称：">
              <el-input
                @keyup.enter.native="filesSerch"
                v-model="tableFormatData.cardBagCategory.files.nickName"
                placeholder="请输入用户昵称"
                style="width: 160px"
              ></el-input>
            </el-form-item>
            <el-form-item label="手机号：">
              <el-input
                @keyup.enter.native="filesSerch"
                v-model="tableFormatData.cardBagCategory.files.mobile"
                placeholder="请输入手机号："
                style="width: 160px"
              ></el-input>
            </el-form-item>
            <el-form-item label="门店id：">
              <el-input
                @keyup.enter.native="filesSerch"
                v-model="tableFormatData.cardBagCategory.files.store_id"
                placeholder="请输入门店id："
                style="width: 160px"
              ></el-input>
            </el-form-item>
            <el-form-item label="卡信息：">
              <el-select filterable v-model="tableFormatData.cardBagCategory.files.card_id" placeholder="请选择或输入关键词搜索">
                <el-option v-for="item in cardCate" :key="item.card_id" :label="item.title" :value="item.card_id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form-item>
          <el-form-item class="filter">
            <el-form-item label="商家id：">
              <el-input
                @keyup.enter.native="filesSerch"
                v-model="tableFormatData.cardBagCategory.files.bus_id"
                placeholder="请输入商家id"
                style="width: 160px"
              ></el-input>
            </el-form-item>
            <el-form-item label="核销店员id："> 
              <el-input
                @keyup.enter.native="filesSerch"
                v-model="tableFormatData.cardBagCategory.files.check_clerk"
                placeholder="请输入核销店员id"
                style="width: 160px"
              ></el-input>
            </el-form-item>
          </el-form-item>
          <el-form-item label="" class="filter-btns">
            <el-button v-waves type="primary" @click="filesSerch"
              >筛选</el-button
            >
            <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 工具条区域 end -->
      <!-- 表格区域 -->
      <div class="wlm-table-content">
        <el-table
          :ref="tableFormatData.cardBagCategory.key"
          :default-sort="{ prop: 'sort', order: 'descending' }"
          :data="tableFormatData.cardBagCategory.tableData"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <el-table-column prop="name" label="用户信息">
            <template slot-scope="scope">
              <el-row type="flex" align="middle" :gutter="8">
                <el-col style="width: auto">
                  <el-avatar
                    size="medium"
                    :src="scope.row.avatarUrl"
                  ></el-avatar>
                </el-col>
                <el-col style="width: auto">
                  <span>{{ scope.row.nickName }}</span>
                </el-col>
              </el-row>
            </template>
          </el-table-column>
          <el-table-column prop="mobile" label="手机号" />
          <el-table-column prop="title" label="卡信息" />
          <el-table-column prop="hx_number" label="使用次数" />
          <el-table-column prop="store_name" label="使用门店" />
          <el-table-column prop="dy_name" label="核销员" />
          <el-table-column prop="check_time" label="核销时间">
            <template slot-scope="scope">
              {{ scope.row.check_time | parseTime("{y}-{m}-{d} {h}:{i}:{s}") }}
            </template>
          </el-table-column>
          <el-table-column prop="have_number" label="核销后剩余次数" />
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c">
          <el-pagination
            :disabled="!hasTableData"
            @size-change="listPageChange"
            @current-change="listPageChange"
            :current-page.sync="tableFormatData.cardBagCategory.pagination.page"
            :page-sizes="tableFormatData.cardBagCategory.pagination.pagesizes"
            :page-size.sync="
              tableFormatData.cardBagCategory.pagination.list_rows
            "
            layout="total, sizes, prev, pager, next, jumper"
            :total="
              hasTableData
                ? tableFormatData.cardBagCategory.pagination.total
                : 0
            "
          >
          </el-pagination>
        </div>
      </div>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import fp from 'lodash/fp'
import { cardUseLists,cardLists } from "@/api/cardBag";
import mixins from "@/mixins/mixins";
import ChooseFiles from "@/components/ChooseFiles/index";
import waves from '@/directive/waves'
export default {
  mixins: [mixins.getters("Table")],
  components: {
    ChooseFiles,
  },
  directives: {
    waves
  },
  data() {
    return {
      // 卡信息列表的数据
      cardCate: [],
      tableFormatData: {
        current: "cardBagCategory",
        cardBagCategory: {
          key: "cardBagCategory",
          api: {
            getList: cardUseLists,
          },
          tableData: [],
          files: {
            nickName: "",
            mobile: '',
            store_id: '',
            bus_id: '',
            check_clerk: '',
            card_id: ''
          },
          rowId: "card_class_id",
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0,
          },
        },
      },
    };
  },
  mounted() {
    this.fetchCardCate()
  },
  methods: {
    showdialog(type, params) {
      if (type === 1) {
        // this.formFormatData=[]
        this.formFormatData.api.submitForm = cardClassSave;
        this.dialogFormVisible = true;
      }
      if (type === 2) {
        this.formFormatData.api.submitForm = cardClassSave;
        this.formFormatDialogEditEvt({
          id: params,
          toggle: "dialogFormVisible",
        });
      }
    },
    saveDialogForm() {
      this.resetDialogFormData({
        name: "",
        sort: "",
        is_show: "",
        image: [],
      });
    },
    fetchCardCate() {
      cardLists({
        page: 1,
        list_rows: 1000
      }).then(res=>{
        this.cardCate = fp.get('data.data.data',res)
        console.log('fetchCardCate res',res)
      })
    }
  },
};
</script>

<style lang="scss" scoped>
</style>